package com.tarena.lbs.service.impl;

import com.tarena.lbs.dto.QrCodeResponse;
import com.tarena.lbs.service.QrCodeService;
import com.tarena.lbs.util.QrCodeUtils;
import com.tarena.lbs.util.UUIDGenerator;
import org.springframework.stereotype.Service;

@Service
public class QrCodeServiceImpl implements QrCodeService {

    @Override
    public QrCodeResponse generateQRCode(String content, int width, int height) {
        QrCodeResponse response = new QrCodeResponse();

        try {
            byte[] qrCodeImage = QrCodeUtils.generateQRCodeImage(content, width, height);

            response.setQrCodeId(UUIDGenerator.generate());
            response.setContent(content);
            response.setImageData(qrCodeImage);

            // TODO: 保存二维码记录到数据库或文件系统

        } catch (Exception e) {
            throw new RuntimeException("Failed to generate QR code", e);
        }

        return response;
    }
}
